package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.CmsMemberReport;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.CmsMemberReportDynamicSqlSupport.*;

@Mapper
public interface CmsMemberReportMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn
            .columnList(id, reportType, reportMemberName, createTime, reportObject, reportStatus, handleStatus, note);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(CmsMemberReport record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(reportType).equalTo(record::getReportType)
                  .set(reportMemberName).equalTo(record::getReportMemberName)
                  .set(createTime).equalTo(record::getCreateTime)
                  .set(reportObject).equalTo(record::getReportObject)
                  .set(reportStatus).equalTo(record::getReportStatus)
                  .set(handleStatus).equalTo(record::getHandleStatus)
                  .set(note).equalTo(record::getNote);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(CmsMemberReport record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(reportType).equalToWhenPresent(record::getReportType)
                  .set(reportMemberName).equalToWhenPresent(record::getReportMemberName)
                  .set(createTime).equalToWhenPresent(record::getCreateTime)
                  .set(reportObject).equalToWhenPresent(record::getReportObject)
                  .set(reportStatus).equalToWhenPresent(record::getReportStatus)
                  .set(handleStatus).equalToWhenPresent(record::getHandleStatus)
                  .set(note).equalToWhenPresent(record::getNote);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<CmsMemberReport> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("CmsMemberReportResult")
    Optional<CmsMemberReport> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "CmsMemberReportResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT),
            @Result(column = "report_type", property = "reportType", jdbcType = JdbcType.INTEGER),
            @Result(column = "report_member_name", property = "reportMemberName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "report_object", property = "reportObject", jdbcType = JdbcType.VARCHAR),
            @Result(column = "report_status", property = "reportStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "handle_status", property = "handleStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "note", property = "note", jdbcType = JdbcType.VARCHAR)
    })
    List<CmsMemberReport> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, cmsMemberReport, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, cmsMemberReport, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(CmsMemberReport record) {
        return MyBatis3Utils.insert(this::insert, record, cmsMemberReport, c ->
                c.map(reportType).toProperty("reportType")
                 .map(reportMemberName).toProperty("reportMemberName")
                 .map(createTime).toProperty("createTime")
                 .map(reportObject).toProperty("reportObject")
                 .map(reportStatus).toProperty("reportStatus")
                 .map(handleStatus).toProperty("handleStatus")
                 .map(note).toProperty("note")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(CmsMemberReport record) {
        return MyBatis3Utils.insert(this::insert, record, cmsMemberReport, c ->
                c.map(reportType).toPropertyWhenPresent("reportType", record::getReportType)
                 .map(reportMemberName).toPropertyWhenPresent("reportMemberName", record::getReportMemberName)
                 .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
                 .map(reportObject).toPropertyWhenPresent("reportObject", record::getReportObject)
                 .map(reportStatus).toPropertyWhenPresent("reportStatus", record::getReportStatus)
                 .map(handleStatus).toPropertyWhenPresent("handleStatus", record::getHandleStatus)
                 .map(note).toPropertyWhenPresent("note", record::getNote)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<CmsMemberReport> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, cmsMemberReport, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<CmsMemberReport> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, cmsMemberReport, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<CmsMemberReport> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, cmsMemberReport, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, cmsMemberReport, completer);
    }
}
